/*接口数据查询类
Created on 2020年05月10日
@author: zxyong 13738196011
 */

package com.zxy.business;

import java.io.IOException;
import java.lang.reflect.Field;
import java.net.Socket;
import java.net.URLDecoder;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zxy.common.Com_Fun;
import com.zxy.common.Com_Para;
import com.zxy.common.ParamName_InterFace;
import com.zxy.db1.Db_Common1;
import com.zxy.db10.Db_Common10;
import com.zxy.db2.Db_Common2;
import com.zxy.db3.Db_Common3;
import com.zxy.db4.Db_Common4;
import com.zxy.db5.Db_Common5;
import com.zxy.db6.Db_Common6;
import com.zxy.db7.Db_Common7;
import com.zxy.db8.Db_Common8;
import com.zxy.db9.Db_Common9;
import com.zxy.main.Init_Page;
import com.zxy.model.Return_Value;
import com.zxy.model.T_DB_CONFIG;
import com.zxy.model.T_PROC_INPARAM;
import com.zxy.model.T_PROC_OUTPARAM;
import com.zxy.model.T_PROC_RETURN;
import com.zxy.tcp.DelayDataThread;

public class Query_Data
{
	public String		session_id	= "";
	public Return_Value	rv			= new Return_Value();

	public Query_Data()
	{
	}

	public Query_Data(Return_Value trv)
	{
		rv = trv;
	}

	public StringBuilder GetDataList(String sub_code,String sub_usercode,String param_name,ArrayList<String> aryParamValue,StringBuilder strUrl,String delay_data,String delay_code,String strIP)
	{
		StringBuilder sbd = new StringBuilder();
		Power_Control pcl = new Power_Control(sub_code,sub_usercode,param_name,strIP);
		if(pcl.getTss().MAIN_ID == -1)
		{
			sbd = pcl.getError();
			if(!sbd.toString().equals(""))
			{
				this.rv.s_result = 0;
				this.rv.err_desc = sbd;
			}
			if(Com_Para.htServSockets.size() > 0)
			{
				try
				{
					Ope_DB_Cent opd = new Ope_DB_Cent();
					String Child_Node = opd.Get_Child_Node(param_name);
					Analyse_Data ad = new Analyse_Data();
					if(Com_Para.htChildNode == null)
					{
						this.rv.s_result = 0;
						this.rv.err_desc.delete(0,this.rv.err_desc.length());
						this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"子级设备未正常连接01\"}]}");
						sbd.delete(0,sbd.length());
						sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"子级设备未正常连接01\"}]}");
						return sbd;
					}
					String skStr = Com_Fun.NoNull(Com_Para.htChildNode.get(Child_Node));
					Socket sk = (Socket)(Com_Para.htServSockets.get(skStr));
					if(sk != null && sk.isConnected())
					{
						Com_Para.htChildInfo.put(Child_Node,"");
						// 请求业务数据
						ad.Send02(strUrl,sk);
						Date dtSBegin = new Date();
						Date dtSEnd = new Date();
						long times = 0;
						while(times < Com_Para.TimeCount && (Com_Para.htChildInfo.get(Child_Node) == null || Com_Para.htChildInfo.get(Child_Node).equals("")))
						{
							times = dtSEnd.getTime() - dtSBegin.getTime();
							dtSEnd = new Date();
						}
						if(Com_Para.htChildInfo.get(Child_Node) == null || Com_Para.htChildInfo.get(Child_Node).equals("") == false)
						{
							sbd.delete(0,sbd.length());
							sbd.append(Com_Para.htChildInfo.get(Child_Node));
							Com_Para.htChildInfo.put(Child_Node,"");
							Com_Para.htTempChildInfo.put(Child_Node,"");
						}
						else
						{
							this.rv.s_result = 0;
							this.rv.err_desc.delete(0,this.rv.err_desc.length());
							this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"获取子级设备数据超时\"}]}");
							sbd.delete(0,sbd.length());
							sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"获取子级设备数据超时\"}]}");
						}
					}
					else
					{
						Com_Para.htServSockets.remove(skStr);
						this.rv.s_result = 0;
						this.rv.err_desc.delete(0,this.rv.err_desc.length());
						this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"发送子级设备数据失败:Mod_Data.htChildNode获取失败,socket断开\"}]}");
						sbd.delete(0,sbd.length());
						sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"发送子级设备数据失败:Mod_Data.htChildNode获取失败,socket断开\"}]}");
					}
				}
				catch(Exception e)
				{
					this.rv.s_result = 0;
					this.rv.err_desc.delete(0,this.rv.err_desc.length());
					this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"发送子级设备数据失败:" + e.toString() + "\"}]}");
					sbd.delete(0,sbd.length());
					sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"发送子级设备数据失败" + e.getMessage() + "\"}]}");
				}
			}
			else
			{
				this.rv.s_result = 0;
				// this.rv.err_desc.delete(0,this.rv.err_desc.length());
				// this.rv.err_desc.append("{\""
				// + param_name
				// +
				// "\":[{\"s_result\":\"0\",\"error_desc\":\"或子级设备未正常连接\"}]}");
			}
		}
		else
		{
			// 延时获取数据 从文件中读取
			if(delay_data.equals("1") && delay_code.length() == 32)
			{
				try
				{
					com.zxy.adminlog.UsAdmin_Log uL = new com.zxy.adminlog.UsAdmin_Log(Com_Para.ApplicationPath,sbd,0);
					sbd.delete(0,sbd.length());
					sbd.append(uL.ReadData(delay_code,param_name));
				}
				catch(IOException e)
				{
					this.rv.s_result = 0;
					this.rv.err_desc.delete(0,this.rv.err_desc.length());
					this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"延时获取数据失败:" + e.getMessage() + "\"}]}");
				}
			}
			// 延时请求数据,将数据写入文件中
			else if(delay_data.equals("0") && delay_code.length() == 32)
			{
				DelayDataThread st = new DelayDataThread(pcl,sub_code,param_name,aryParamValue,delay_code,strIP);
				st.start();
				sbd.delete(0,sbd.length());
				sbd.append("{\"s_result\":\"1\",\"error_desc\":\"请求延时数据成功,请稍候获取数据\"}");
			}
			else
			{
				sbd.delete(0,sbd.length());
				sbd = Cal_Data(pcl,sub_code,param_name,aryParamValue,strIP);
			}
		}

		if(param_name.equals("APP_USER_ZXY"))
		{
			JSONObject jso = null;
			try
			{
				jso = new JSONObject(sbd.toString());
				JSONArray jsoary = jso.getJSONArray("APP_USER_ZXY");
				String strNextInfName = "";
				for(int i = 0;i < jsoary.length();i++)
				{
					JSONObject temobj = jsoary.getJSONObject(i);
					String strINFNAME = temobj.getString("INF_EN_NAME");
					if(!strINFNAME.equals(strNextInfName))
					{
						ArrayList<String> arySubParamValue = new ArrayList<String>();
						if(temobj.getString("URL_IN_PARAM").length() > 0)
						{
							int k = 0;
							for(String strtemParam: temobj.getString("URL_IN_PARAM").split(","))
							{
								strtemParam = aryParamValue.get(Integer.valueOf(strtemParam.replaceAll("param_value","")) - 1);
								arySubParamValue.add(k,strtemParam);
								k++;
							}
						}
						pcl = new Power_Control(sub_code,sub_usercode,strINFNAME,strIP);
						JSONObject jsonSub = new JSONObject(Cal_Data(pcl,sub_code,strINFNAME,arySubParamValue,strIP).toString());
						jso.put(strINFNAME,jsonSub.getJSONArray(strINFNAME));
						strNextInfName = strINFNAME;
					}
				}
				sbd.delete(0,sbd.length());
				sbd.append(jso.toString());
			}
			catch(JSONException e)
			{
				sbd.delete(0,sbd.length());
				sbd.append("{\"s_result\":\"1\",\"error_desc\":\"读取APP_USER_ZXY接口失败(GetDataList)JSONException" + e.getMessage() + "\"}");
			}
		}
		return sbd;
	}

	// def Get_Log(self,inputParam_name,param_path,inputSession_id):
	// if self.Get_eova_user_rid(Com_Fun.getLogin_Id(inputSession_id)) != 1:
	// return
	// "{\""+inputParam_name+"\": [{\"s_result\": 0, \"error_desc\": \"禁止操作，用户权限不足!\"}]}"
	//
	// temLogPath = Com_Para.ApplicationPath+'/log/'+param_path
	// jso = {}
	// jsary = []
	// iIndex = 1
	// for parent,dirnames,filenames in os.walk(temLogPath, followlinks=True):
	// for dirname in dirnames:
	// temjso = {}
	// temjso["MAIN_ID"] = str(iIndex)
	// temjso["file_type"] = "文件夹"
	// temjso["file_name"] = dirname
	// iIndex = iIndex + 1
	// jsary.append(temjso)
	//
	// for filename in filenames:
	// temjso = {}
	// temjso["MAIN_ID"] = str(iIndex)
	// temjso["file_type"] = "日志文件"
	// temjso["file_name"] = filename
	// iIndex = iIndex + 1
	// jsary.append(temjso)
	//
	// jso[inputParam_name] = jsary
	// temResult = json.dumps(jso,ensure_ascii=False)
	// return temResult

	public StringBuilder Cal_Data(Power_Control pcl,String sub_code,String param_name,ArrayList<String> aryParamValue,String strIP)
	{
		Ope_DB_Cent opd = new Ope_DB_Cent();
		StringBuilder sbd = new StringBuilder();
		if(param_name.equals("init_page"))
		{
			Init_Page.Init_Load();
			sbd.append("{\"" + param_name + "\":[{\"s_result\":\"1\",\"error_desc\":\"读取缓存信息成功!\"}]}");
			return sbd;
		}
		// else if(param_name.equals("init_log"))
		// {
		// Init_Page.Init_Load();
		// sbd.append("{\"" + param_name +
		// "\":[{\"s_result\":\"1\",\"error_desc\":\"读取缓存信息成功!\"}]}");
		// return sbd;
		// }

		if(!pcl.getError().toString().equals(""))
		{
			sbd.append(pcl.getError());
			this.rv.s_result = 0;
			this.rv.err_desc = sbd;
			return sbd;
		}
		List<T_PROC_INPARAM> tpinpas = opd.Get_T_PROC_INPARAM(pcl.getTpn().MAIN_ID);
		List<T_PROC_OUTPARAM> tpoutpas = opd.Get_T_PROC_OUTPARAM(pcl.getTpn().MAIN_ID);
		List<T_PROC_RETURN> tprtns = opd.Get_T_PROC_RETURN(pcl.getTpn().MAIN_ID);
		/*
		 * ProName 存储过程名 Parameters输入参数 ParamTypes参数类型String Int float Date
		 * ParamOutName输出参数名 ParamOutType输出参数类型
		 */
		String[] Parameters = new String[tpinpas.size()];
		String[] ParamTypes = new String[tpinpas.size()];
		String[] ParamOutName = new String[tpoutpas.size()];
		String[] ParamOutType = new String[tpoutpas.size()];
		// 传入参数
		for(int i = 0;i < Parameters.length;i++)
		{
			T_PROC_INPARAM tpi = (T_PROC_INPARAM)(tpinpas.get(i));
			String strTem = aryParamValue.get(i).toString();
			if(tpi.IS_URLENCODE == 1 && !strTem.equals(""))
			{
				try
				{
					Parameters[i] = URLDecoder.decode(strTem,Com_Para.U_CODE);
				}
				catch(Exception ees)
				{
				}
			}
			else Parameters[i] = strTem;
			ParamTypes[i] = tpi.PARAM_TYPE;
		}
		// 接口输入反射类调用
		if(!pcl.getTpn().REFLECT_IN_CLASS.equals(""))
		{
			try
			{
				Class<?> objC = Class.forName(pcl.getTpn().REFLECT_IN_CLASS);
				ParamName_InterFace pni = (ParamName_InterFace)objC.newInstance();
				for(Field field: pni.getClass().getDeclaredFields())
				{
					field.setAccessible(true);
					if(field.getName().equals("strResult"))
						continue;
					else if(field.getName().equals("userid"))
						continue;
					else if(field.getName().equals("param_name"))
					{
						field.set(pni,param_name);
						continue;
					}
					else if(field.getName().equals("session_id"))
					{
						field.set(pni,Com_Fun.GetSessionInfo(session_id));
						continue;
					}
					else if(field.getName().indexOf("param_value") != -1)
					{
						try
						{
							int iInd = Integer.valueOf(field.getName().replaceAll("param_value",""));
							if(aryParamValue.size() >= iInd)
								field.set(pni,aryParamValue.get(iInd - 1).toString());
							else break;
						}
						catch(Exception dsd)
						{
						}
					}
				}
				pni.init_start();
				for(Field field: pni.getClass().getDeclaredFields())
				{
					if(field.getName().equals("userid"))
						continue;
					else if(field.getName().equals("param_name"))
						continue;
					else if(field.getName().equals("session_id"))
						continue;
					else if(field.getName().indexOf("param_value") != -1)
					{
						try
						{
							int iInd = Integer.valueOf(field.getName().replaceAll("param_value",""));
							Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
							if(Parameters.length >= iInd)
								Parameters[iInd - 1] = fieldGetName.toString();
							else break;
						}
						catch(Exception dsd)
						{
						}
					}
					else if(field.getName().equals("strResult"))
					{
						Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
						if(!fieldGetName.toString().equals(""))
						{
							sbd.delete(0,sbd.length());
							sbd.append(fieldGetName.toString());
							return sbd;
						}
					}
				}
			}
			catch(Exception ee)
			{
				System.err.println(pcl.getTpn().REFLECT_IN_CLASS + "接口输入反射类属性值设置或获取失败!" + ee.getMessage());
			}
		}
		// 传出参数
		for(int i = 0;i < ParamOutName.length;i++)
		{
			T_PROC_OUTPARAM tpi = (T_PROC_OUTPARAM)(tpoutpas.get(i));
			ParamOutName[i] = tpi.PARAM_CN_NAME;
			ParamOutType[i] = tpi.PARAM_TYPE;
		}
		// 调用存储过程
		java.sql.ResultSet rs = null;
		Db_Common1 dbc1 = null;
		Db_Common2 dbc2 = null;
		Db_Common3 dbc3 = null;
		Db_Common4 dbc4 = null;
		Db_Common5 dbc5 = null;
		Db_Common6 dbc6 = null;
		Db_Common7 dbc7 = null;
		Db_Common8 dbc8 = null;
		Db_Common9 dbc9 = null;
		Db_Common10 dbc10 = null;
		StringBuilder sqlException = null;
		// 业务子系统数据库操作
		List<T_DB_CONFIG> tdc = opd.Get_T_DB_CONFIG(pcl.getTpn().DB_ID);
		if(tdc.size() == 1)
		{
			switch(((T_DB_CONFIG)tdc.get(0)).getMAIN_ID())
			{
				case 1:
					dbc1 = new Db_Common1();
					rs = dbc1.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc1.sqlException;
					break;
				case 2:
					dbc2 = new Db_Common2();
					rs = dbc2.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc2.sqlException;
					break;
				case 3:
					dbc3 = new Db_Common3();
					rs = dbc3.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc3.sqlException;
					break;
				case 4:
					dbc4 = new Db_Common4();
					rs = dbc4.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc4.sqlException;
					break;
				case 5:
					dbc5 = new Db_Common5();
					rs = dbc5.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc5.sqlException;
					break;
				case 6:
					dbc6 = new Db_Common6();
					rs = dbc6.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc6.sqlException;
					break;
				case 7:
					dbc7 = new Db_Common7();
					rs = dbc7.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc7.sqlException;
					break;
				case 8:
					dbc8 = new Db_Common8();
					rs = dbc8.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc8.sqlException;
					break;
				case 9:
					dbc9 = new Db_Common9();
					rs = dbc9.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc9.sqlException;
					break;
				case 10:
					dbc10 = new Db_Common10();
					rs = dbc10.Common_Sql_Proc(pcl.getTpn().INF_EN_NAME,Parameters,ParamTypes,ParamOutName,ParamOutType,pcl.getTpn());
					sqlException = dbc10.sqlException;
					break;
			}
		}
		try
		{
			JSONObject jso = new JSONObject();
			JSONArray jsary = new JSONArray();
			int iIndex = 0;
			while(rs != null && rs.next() && iIndex < 2000)
			{
				JSONObject temjso = new JSONObject();
				if(iIndex == 0 && Com_Para.Is_UserLogin != "" && Com_Para.Is_UserLogin.indexOf("[" + param_name + "]") != -1)
				{
					// 用户登陆成功
					if(rs.getString("s_result").equals("1"))
					{
						temjso.put("session_id",session_id);
					}
					else
					{
						temjso.put("session_id","");
					}
				}
				String logName = Com_Fun.GetImgPath(param_name);
				// 结果返回值
				for(int i = 0;i < tprtns.size();i++)
				{
					T_PROC_RETURN tpi = (T_PROC_RETURN)(tprtns.get(i));
					if(tpi.RETURN_TYPE.toUpperCase().equals("STRING"))
					{
						temjso.put(tpi.RETURN_NAME,Com_Fun.ReplacePath(logName,Com_Fun.NoNull(rs.getString(tpi.RETURN_NAME)),tpi.IS_IMG,tpi.IS_URLENCODE));
					}
					else if(tpi.RETURN_TYPE.toUpperCase().equals("INT"))
					{
						temjso.put(tpi.RETURN_NAME,rs.getInt(tpi.RETURN_NAME));
					}
					else if(tpi.RETURN_TYPE.toUpperCase().equals("FLOAT"))
					{
						temjso.put(tpi.RETURN_NAME,rs.getFloat(tpi.RETURN_NAME));
					}
					else if(tpi.RETURN_TYPE.toUpperCase().equals("DATE"))
					{
						String strTemDate = "";
						try
						{
							Date dtTem = rs.getDate(tpi.RETURN_NAME) == null ? (new SimpleDateFormat("yyyy-MM-dd").parse("1900-1-1")) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(rs.getString(tpi.RETURN_NAME).replaceAll("T"," ")));
							strTemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dtTem);
						}
						catch(Exception ee)
						{
						}
						temjso.put(tpi.RETURN_NAME,strTemDate);
					}
				}
				// 结果输出值
				for(int i = 0;i < tpoutpas.size();i++)
				{
					T_PROC_OUTPARAM tpi = (T_PROC_OUTPARAM)(tpoutpas.get(i));
					if(tpi.PARAM_TYPE.toUpperCase().equals("STRING"))
					{
						temjso.put(tpi.PARAM_EN_NAME,Com_Fun.ReplacePath(logName,Com_Fun.NoNull(rs.getString(tpi.PARAM_EN_NAME)),0,0));
					}
					else if(tpi.PARAM_TYPE.toUpperCase().equals("INT"))
					{
						temjso.put(tpi.PARAM_EN_NAME,rs.getInt(tpi.PARAM_EN_NAME));
					}
					else if(tpi.PARAM_TYPE.toUpperCase().equals("FLOAT"))
					{
						temjso.put(tpi.PARAM_EN_NAME,rs.getFloat(tpi.PARAM_EN_NAME));
					}
					else if(tpi.PARAM_TYPE.toUpperCase().equals("DATE"))
					{
						String strTemDate = "";
						try
						{
							Date dtTem = rs.getDate(tpi.PARAM_EN_NAME) == null ? (new SimpleDateFormat("yyyy-MM-dd").parse("1900-1-1")) : (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(rs.getString(tpi.PARAM_EN_NAME).replaceAll("T"," ")));
							strTemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dtTem);
						}
						catch(Exception ee)
						{
						}
						temjso.put(tpi.PARAM_EN_NAME,strTemDate);
					}
				}
				jsary.put(temjso);
				iIndex++;
			}
			if(jsary.length() == 0 && !sqlException.toString().equals(""))
			{
				JSONObject temjso = new JSONObject();
				temjso.put("s_result","0");
				if(Com_Para.ShowSqlError == 1)
				{
					temjso.put("error_desc","失败," + sqlException.toString());
				}
				else temjso.put("error_desc","失败,数据库操作出错请查看程序错误日志文件");
				jsary.put(temjso);
			}
			jso.put(pcl.getTpn().INF_EN_NAME,jsary);
			sbd = new StringBuilder();
			sbd.append(jso.toString());
			// 写入用户session相关信息
			if(!session_id.equals(""))
			{
				if(Com_Para.Is_UserLogin != "" && Com_Para.Is_UserLogin.indexOf("[" + param_name + "]") != -1)
					Com_Fun.SetSession(session_id,sbd.toString().replaceAll(param_name,"SESSION_INFO"));
				else
				// 只更新session时间
				Com_Fun.SetSession(session_id,"");
			}
			opd.Ope_Data_Number(pcl.getTsp(),pcl.getTsup(),pcl.getTpn().MAIN_ID);
		}
		catch(SQLException e)
		{
			sbd.delete(0,sbd.length());
			sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"执行该接口出错(Cal_Data)SQLException:" + e.getMessage() + "\"}]}");
			this.rv.s_result = 0;
			this.rv.err_desc.delete(0,this.rv.err_desc.length());
			this.rv.err_desc.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"执行该接口出错(Cal_Data)SQLException:" + e.getMessage() + "\"}]}");
			try
			{
				com.zxy.adminlog.UsAdmin_Log uLs = new com.zxy.adminlog.UsAdmin_Log(Com_Para.ApplicationPath,new StringBuilder("执行接口出错(Cal_Data)\r\n" + "sub_code=" + sub_code + "&param_name=" + param_name + " " + e.getMessage()));
				uLs.WriteLog();
			}
			catch(IOException e1)
			{
			}
		}
		catch(JSONException e)
		{
			sbd.delete(0,sbd.length());
			sbd.append("{\"" + param_name + "\":[{\"s_result\":\"0\",\"error_desc\":\"执行该接口出错(Cal_Data)JSONException:" + e.getMessage() + "\"}]}");
			this.rv.s_result = 0;
			this.rv.err_desc = sbd;
		}
		finally
		{
			try
			{
				if(rs != null)
				{
					rs.getStatement().close();
					rs.close();
				}
				if(dbc1 != null && !dbc1.conn_a.b_nocursor)
				{
					if(dbc1.conn_a != null && dbc1.conn_a.calls != null)
						dbc1.conn_a.calls.close();
				}
				else if(dbc1 != null)
				{
					dbc1.conn_a.returnConnection();
				}
				else if(dbc2 != null && !dbc2.conn_a.b_nocursor)
				{
					if(dbc2.conn_a.calls != null)
						dbc2.conn_a.calls.close();
				}
				else if(dbc2 != null)
				{
					dbc2.conn_a.returnConnection();
				}
				else if(dbc3 != null && !dbc3.conn_a.b_nocursor)
				{
					if(dbc3.conn_a != null && dbc3.conn_a.calls != null)
						dbc3.conn_a.calls.close();
				}
				else if(dbc3 != null)
				{
					dbc3.conn_a.returnConnection();
				}
				else if(dbc4 != null && !dbc4.conn_a.b_nocursor)
				{
					if(dbc4.conn_a != null && dbc4.conn_a.calls != null)
						dbc4.conn_a.calls.close();
				}
				else if(dbc4 != null)
				{
					dbc4.conn_a.returnConnection();
				}
				else if(dbc5 != null && !dbc5.conn_a.b_nocursor)
				{
					if(dbc5.conn_a != null && dbc5.conn_a.calls != null)
						dbc5.conn_a.calls.close();
				}
				else if(dbc5 != null)
				{
					dbc5.conn_a.returnConnection();
				}
				else if(dbc6 != null && !dbc6.conn_a.b_nocursor)
				{
					if(dbc6.conn_a != null && dbc6.conn_a.calls != null)
						dbc6.conn_a.calls.close();
				}
				else if(dbc6 != null)
				{
					dbc6.conn_a.returnConnection();
				}
				else if(dbc7 != null && !dbc7.conn_a.b_nocursor)
				{
					if(dbc7.conn_a != null && dbc7.conn_a.calls != null)
						dbc7.conn_a.calls.close();
				}
				else if(dbc7 != null)
				{
					dbc7.conn_a.returnConnection();
				}
				else if(dbc8 != null && !dbc8.conn_a.b_nocursor)
				{
					if(dbc8.conn_a != null && dbc8.conn_a.calls != null)
						dbc8.conn_a.calls.close();
				}
				else if(dbc8 != null)
				{
					dbc8.conn_a.returnConnection();
				}
				else if(dbc9 != null && !dbc9.conn_a.b_nocursor)
				{
					if(dbc9.conn_a != null && dbc9.conn_a.calls != null)
						dbc9.conn_a.calls.close();
				}
				else if(dbc9 != null)
				{
					dbc9.conn_a.returnConnection();
				}
				else if(dbc10 != null && !dbc10.conn_a.b_nocursor)
				{
					if(dbc10.conn_a != null && dbc10.conn_a.calls != null)
						dbc10.conn_a.calls.close();
				}
				else if(dbc10 != null)
				{
					dbc10.conn_a.returnConnection();
				}
			}
			catch(SQLException e)
			{
			}
		}
		// 接口结果值输出反射类调用
		if(!pcl.getTpn().REFLECT_OUT_CLASS.equals(""))
		{
			try
			{
				Class<?> objC = Class.forName(pcl.getTpn().REFLECT_OUT_CLASS);
				ParamName_InterFace pni = (ParamName_InterFace)objC.newInstance();
				for(Field field: pni.getClass().getDeclaredFields())
				{
					field.setAccessible(true);
					if(field.getName().equals("strResult"))
					{
						field.set(pni,sbd);
						continue;
					}
					else if(field.getName().equals("param_name"))
					{
						field.set(pni,param_name);
						continue;
					}
					else if(field.getName().indexOf("param_value") != -1)
					{
						try
						{
							int iInd = Integer.valueOf(field.getName().replaceAll("param_value",""));
							if(aryParamValue.size() >= iInd)
								field.set(pni,aryParamValue.get(iInd - 1).toString());
							else break;
						}
						catch(Exception dsd)
						{
						}
					}
				}
				pni.init_start();
				for(Field field: pni.getClass().getDeclaredFields())
				{
					// 获取属性值
					if(field.getName().equals("strResult"))
					{
						Object fieldGetName = Com_Fun.getFieldValueByName(field.getName(),pni);
						return (StringBuilder)fieldGetName;
					}
				}
			}
			catch(Exception ee)
			{
				System.err.println(pcl.getTpn().REFLECT_OUT_CLASS + "接口结果值输出反射类调用失败!" + ee.getMessage());
			}
		}
		return sbd;
	}
}